package learn.config;

import learn.servlet.MyServletContextListener;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: 2种方法注入
 * 1、添加webServlet注解（webFilter \ webListener)
 * 2、注入 ServletRegistrationBean FilterRegistrationBean ServletListenerRegistrationBean
 * @Author yxc
 * @Date 2022/1/8
 */
@Configuration
public class MyRegistConfig {

//    @Bean
//    public ServletRegistrationBean MyServlet(){
//        MyServlet myServlet = new MyServlet();
//        return new ServletRegistrationBean(myServlet,"/my");
//    }

//    @Bean
//    public FilterRegistrationBean myFilter(){
//        MyFilter myFilter = new MyFilter();
//        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
//        filterRegistrationBean.setUrlPatterns(Arrays.asList("/my"));
//        return filterRegistrationBean;
//    }

    @Bean
    public ServletListenerRegistrationBean myListener() {
        MyServletContextListener myServletContextListener = new MyServletContextListener();
        return new ServletListenerRegistrationBean(myServletContextListener);
    }
}
